<template>
  <div class="dialog-container">
    <el-dialog
      :title="'批量审核'"
      :visible="batchHandleDialogVisible"
      @open="initData"
      @close="closeDialog"
    >
      <el-table
        class="grid-data-table"
        :data="taskList"
      >
        <el-table-column align="center" type="index" width="80" />
        <el-table-column prop="num" label="任务编号" show-overflow-tooltip />
        <el-table-column prop="taskName" label="任务名称" />
        <el-table-column prop="taskContent" label="任务内容" show-overflow-tooltip />
        <el-table-column prop="projectDepartmentName" label="项目部" /></el-table>
      <el-form
        ref="form"
        :model="dataForm"
        class="dialog-form"
        label-width="110"
        size="mini"
      >
        <el-row>
          <el-form-item label="审核意见">
            <el-radio-group v-model="dataForm.taskStatus">
              <el-radio
                v-for="(item,index) in reviewStatusList"
                :key="index + 'task_status'"
                :label="item.code"
              >{{ item.codeName }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item :label="'意见说明'" prop="statusDescription">
            <el-input v-model="dataForm.statusDescription" type="textarea" placeholder="" rows="5" />
          </el-form-item>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button :loading="saveLoading" class="sure-btn" size="mini" type="primary" @click="handleBatchUpdate()">提交</el-button>
        <el-button size="mini" class="cancel-btn" @click="closeDialog">取消</el-button>
      </span>·
    </el-dialog>

  </div>
</template>

<script>
import { batchReview } from '@/api/info/task'
import { getDictLabel } from '@/utils'
import { getDict } from '@/utils/dict'

export default {
  name: 'BatchHandle',
  props: {
    batchHandleDialogVisible: {
      type: Boolean,
      default: false
    },
    dialogType: {
      type: String,
      default: 'batchHandle'
    },
    ids: {
      type: Array,
      default: null
    },
    taskList: {
      type: Array,
      default: null
    }
  },
  data() {
    return {
      saveLoading: false,
      dataForm: {
        taskStatus: 'e009_03',
        statusDescription: null,
        ids: []
      },
      reviewStatusList: [],
      taskStatus: []
    }
  },
  created() {
    this.taskStatus = getDict('e009')
  },
  methods: {
    getDictLabel,
    initData() {
      this.taskStatus.forEach(item => {
        if (item.code === 'e009_03' || item.code === 'e009_04') {
          this.reviewStatusList.push(item)
        }
      })
      this.dataForm.ids = this.ids
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    handleBatchUpdate() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$confirm('确认批量审核 ' + this.dataForm.ids.length + ' 条选中的任务吗?', '提示', {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.saveLoading = true
            batchReview(this.dataForm).then(() => {
              this.$message.success('成功')
              this.$emit('closeDialog')
              this.$emit('flushPage')
              this.saveLoading = false
            }).catch(() => {
              this.saveLoading = false
            })
          }).catch(() => {
          })
        }
      })
    },
    closeDialog() {
      this.$emit('closeDialog')
      this.clearData()
      this.$refs['form'].clearValidate()
    },
    clearData() {
      this.dataForm = {
        taskStatus: 'e009_03',
        statusDescription: null,
        ids: null
      }
      this.reviewStatusList = []
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
